<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<div>
    <input type="text" placeholder="请输入0-100之间的整数" v-model="num">
    <input type="button" value="猜一猜" @click="f1()">
    <input type="button" value="充值5次" @click="f(1)">
    <input type="button" value="充值10次" @click="f(2)">
    <input type="button" value="重新开始" @click="f(3)">
    <h1>结果:{{info}}</h1>
</div>

<script src="js/vue.js"></script>
<script>
    let x = parseInt(Math.random() * 101);
    let times = 5;
    let v = new Vue({
        el: "div",
        data: {
            info: "",
            num: "",

        },

        methods: {
            f1() {
                if (isNaN(v.num)) {
                    v.info = "输入的内容格式有误，请重新输入"
                }else {
                    if (v.num < x) {
                        --times;
                        if (times < 1) {
                            v.info = "猜小了，您的机会已用完，请充值!"
                        } else {
                            v.info = "猜小了,您还有" + times + "次机会!"
                        }

                    } else if (v.num > x) {
                        --times;
                        if (times < 1) {
                            v.info = "猜大了，您的机会已用完，请充值!"
                        } else {
                            v.info = "猜大了,您还有" + times + "次机会!"
                        }

                    } else if (v.num = x) {
                        v.info = "恭喜您!猜对了";
                        times = 0;
                        x = parseInt(Math.random() * 101);
                    }

                }
            },


            f(x) {

                switch (x) {
                    case 1:
                        times += 5;
                        v.info = "已成功充值5次,总次数为" + times
                        break;
                    case 2:
                        times += 10;
                        v.info = "已成功充值10次,总次数为" + times
                        break;
                    case 3:
                        times = 5;
                        v.info = "开始新的一轮"
                }

            }

        },

    })

</script>

</body>
</html>